//package com.csust.travel.service.impl;
//
//import com.csust.travel.entity.NewUsers;
//import com.csust.travel.entity.User;
//import com.csust.travel.exception.ServiceExceptionPlus;
//import com.csust.travel.mapper.NewUsersMapper;
//import com.csust.travel.util.TokenUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//@Service
//public class UserTokenService {
//    @Autowired
//    NewUsersMapper newUsersMapper;
//
//
//    public User login(NewUsers newUsers){
//        User  dbUser = newUsersMapper.findUserByUsername(newUsers.getUsername());
//        if (dbUser ==null){
//            throw new ServiceExceptionPlus("该用户未注册");
//        }
//        System.out.println("123"+dbUser);
//        System.out.println("142"+newUsers.getPassword());
//        System.out.println("143"+dbUser.getPassword());
//        if (!newUsers.getPassword().equals(dbUser.getPassword())){
//            throw new ServiceExceptionPlus("用户名或密码错误");
//        }
//
//        //生成 Token
//
//        newUsersMapper.updateTime(dbUser.getId());
//        String token = TokenUtils.createToken(dbUser.getId().toString(), dbUser.getPassword());
//        dbUser.setToken(token);
//        return dbUser;
//    }
//
//    public NewUsers register(NewUsers newUsers){
//        User dbUser = newUsersMapper.findUserByUsername(newUsers.getUsername());
//        if (dbUser !=null){
//            throw new ServiceExceptionPlus("用户名已存在");
//        }
//        newUsers.setRole("用户");
//        newUsersMapper.addUser(newUsers);
//
//        return newUsers;
//    }
//
//}
//
